<?php 

$template->setTemplateFile('update_commune_form','tpl/update_commune_form.tpl');
if (isset($_GET['update_cpcommune']) && isset($_GET['update_cpnom'])) {
	$cpc = $_GET['update_cpcommune'];
	$cpnom = sql_protect(html_escape($_GET['update_cpnom']));
	$template->parseTemplate('update_commune_form',"COMMUNE_CP",$cpc);
	$template->parseTemplate('update_commune_form',"COMMUNE_NOM",$cpnom);
}
	$template->setTemplateFile('center','tpl/center.tpl');
	$template->parseTemplate('center',"CENTER_CONTENT",$template->getTemplate('update_commune_form'));
	
if (isset($_POST['cp2']) && isset($_POST['nomc2'])) {
	$cpr = $_POST['cp2'];
	$nomcr = sql_protect(html_escape($_POST['nomc2']));
	if(strlen($cpr)==5 && $cpr>'00000' && $cpr<'99999') {
	$req = SGBD::query(
		"UPDATE commune
		SET cpcommune='$cpr', nomcommune='$nomcr'
		WHERE cpcommune='$cpc';" );
	if($req)
		header("Location: index.php?page=admin_communes");
	}

}

?>